﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data.Common;
using Data.Enum;
using DataAccess.FinancialManage;
using Microsoft.Reporting.WinForms;
using WinForm.Helper;

namespace WinForm.Reports
{
    public partial class PrintFinBillFrm : Form
    {
        /// <summary>
        ///     报表所在目录
        /// </summary>
        private static string _rdlcPath = "Rdlcs\\{0}";

        /// <summary>
        /// 报表名称
        /// </summary>
        private static string _rdlcName;

        /// <summary>
        /// 展示数据开始时间
        /// </summary>
        private DateTime _beginTime = DateTime.Now.AddDays(-1);

        /// <summary>
        /// 展示数据结束时间
        /// </summary>
        private DateTime _endTime = DateTime.Now;

        /// <summary>
        /// 展示数据站点id
        /// </summary>
        private Int64 _opAddressid;

        public PrintFinBillFrm()
        {
            InitializeComponent();
        }

        public PrintFinBillFrm(string rdlcName, DateTime beginTime, DateTime endTime, Int64 opAddressId)
        {
            _rdlcName = rdlcName;
            _beginTime = beginTime;
            _endTime = endTime;
            _opAddressid = opAddressId;
            InitializeComponent();
        }

        private void PrintFinBillFrm_Load(object sender, EventArgs e)
        {
            string errorMessage = string.Empty;
            try
            {
                reportViewer1.ProcessingMode = ProcessingMode.Local;
                reportViewer1.LocalReport.ReportPath = string.Format(_rdlcPath, _rdlcName);


                //设置参数
                var cPerson =
                    new ReportParameter("CreateReportPerson",
                        SystemInfo.OperateName);
                var cTime =
                    new ReportParameter("CreateReportTime", DateTime.Now.ToString());
                var cAddress =
                    new ReportParameter("CreateReportAddress",
                        SystemInfo.OperateAddress);
                reportViewer1.LocalReport.SetParameters(new List<ReportParameter> { cPerson, cTime, cAddress });
                IFinancial _f = new Financial();
                ResultInfo<DataSet> businessvs = _f.GetPropertiesDs(_opAddressid, _beginTime, _endTime);
                if (businessvs.ResultNumber == ResultEnum.Success)
                {
                    reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", businessvs.Obj.Tables[0]));

                    reportViewer1.RefreshReport();
                }else
                {
                    MyMessageBox.ShowMessageBoxInfo("当前记录为空！");
                }

            }
            catch (Exception e1)
            {
                errorMessage = errorMessage + e1.Message;
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                MyMessageBox.ShowMessageBoxInfo(errorMessage);
            }
        }
    }
}
